package com.ferris.redbook.mapper;

import com.ferris.redbook.entity.Post;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PostMapper extends BaseMapper<Post> {

    /**
     * 查询用户帖子列表
     */
    @Select("SELECT * FROM posts WHERE user_id = #{userId} AND status = 1 ORDER BY created_at DESC LIMIT #{limit} OFFSET #{offset}")
    List<Post> selectUserPosts(@Param("userId") Long userId, @Param("offset") int offset, @Param("limit") int limit);

    /**
     * 统计用户帖子数量
     */
    @Select("SELECT COUNT(*) FROM posts WHERE user_id = #{userId} AND status = 1")
    long countUserPosts(@Param("userId") Long userId);

    /**
     * 查询帖子图片
     */
    @Select("SELECT image_url FROM post_images WHERE post_id = #{postId} ORDER BY sort_order")
    List<String> selectPostImages(@Param("postId") Long postId);
}